﻿using System;
using System.Collections;
using System.Data;
using Lib.Data;
using Lib.Utils;


namespace SysObj
{
    public class Dv_ChuyenDoi : IDisposable
    {
        DataLayer m_DataLayer;

        public Dv_ChuyenDoi()
        {
            m_DataLayer = new DataLayer();
        }

        public void Dispose()
        {
            try
            {
                if (this.m_DataLayer != null)
                {
                    this.m_DataLayer.Dispose();
                }
                this.m_DataLayer = null;
            }
            catch
            {
            }
        }

        public DataTable LoadData()
        {
            return m_DataLayer.ExecDataTable("Sp_Dv_ChuyenDoi", " Command", "LoadData");
        }

        public void Update(DataTable DT)
        {
            try
            {
                m_DataLayer.BeginTransaction();

                m_DataLayer.ExecNonQuery("Sp_Dv_ChuyenDoi", " Command", "DeleteAll");

                foreach (DataRow row in DT.Rows)
                {
                    m_DataLayer.ExecNonQuery("Sp_Dv_ChuyenDoi", "Command,IdDVT,TyLe,IdDVT2", "Update",
                        Cvert.ToInt32(row["IdDVT"], 0), Cvert.ToDecimal(row["TyLe"], 0),
                        Cvert.ToInt16(row["IdDVT2"], 0));
                }

                m_DataLayer.CommitTransaction();
            }
            catch (Exception ex)
            {
                m_DataLayer.RollbackTransaction();
                throw ex;
            }
        }
    }
}
